package com.atguigu.day17.test02;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

/**
 * @author fenge
 */
public class Test02 {
    public static void main(String[] args) {
        System.out.println("乐透号码已经生成,游戏开始:");
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int i = 0; i < 10; ) {
            int rand = (int) (Math.random() * 50) + 1;
            if (!arrayList.contains(rand)) {
                arrayList.add(rand);//0,50 50-0+1+0
                i++;
            }
        }
        ArrayList<Integer> subArrayList = new ArrayList<>();
        Scanner s = new Scanner(System.in);
        for (int i = 0; i < 10;) {
            System.out.printf("请输入第%d个数字:[1-50]\n", i+1);
            int rand = s.nextInt();
            if (!subArrayList.contains(rand)) {
                subArrayList.add(rand);//0,50 50-0+1+0
                i++;
            }else
                System.out.println("输入的数字重复了,请重新输入");
//            subArrayList.add(s.nextInt());
        }
        System.out.print("您输入的号码为:");
        Iterator i = arrayList.iterator();
        Iterator subI = subArrayList.iterator();
        for (Integer integer : subArrayList) {
            System.out.print(subI.next().toString() + ",");
        }
        System.out.print("\n乐透号码为:");
        int count = 0;
        for (Integer integer : arrayList) {
            System.out.print(i.next().toString() + ",");
        }
        for (Integer integer : arrayList) {
            for (Integer integer1 : subArrayList) {
                if (integer == integer1)
                    count++;
            }
        }
        System.out.println("\n猜中了:" + count+"个数字");
    }
}
